<?php
/**
 * @file : celebrity.php
 * @date : 2014-12-26
 * @author : yuebin
 */
namespace haibao\cms\business;

use haibao\cms\common\ChineseSpell;
use haibao\cms\data\Celebrity as CelebrityData; 
use haibao\cms\data\CelebrityInfo as CelebrityInfoData;
use haibao\cms\data\CelebrityImage as CelebrityImageData;
use haibao\cms\data\BrandRelStar as BrandRelStarData;
use haibao\cms\data\CelebrityRelation as CelebrityRelationData;
use haibao\cms\model\data\Tag as TagModel; 
use haibao\frame\data\query\Condition;
use haibao\cms\model\filter\Celebrity as CelebrityFilter;
use haibao\cms\model\filter\CelebrityImage as CelebrityImageFilter;
use haibao\cms\model\filter\CelebrityInfo as CelebrityInfoFilter;
use haibao\cms\model\filter\CelebrityRiseCount as CelebrityRiseCountFilter;
use haibao\cms\model\data\Celebrity as CelebrityModel;


class Celebrity extends \haibao\cms\business\Base{

	public static $celebrityGender = array(
			CelebrityModel::GENDER_MALE =>'男性',
			CelebrityModel::GENDER_FEMALE =>'女性',
	);
	
	public static $category = array(
			CelebrityModel::UN_ONELINE =>'非一线明星',
			CelebrityModel::ONELINE =>'一线明星',
	);
	
	public static $celebrityArea = array(
			CelebrityModel::PlACE_EUROPE_AMERICA =>'欧美',
			CelebrityModel::PlACE_JAPAN =>'日本',
			CelebrityModel::PlACE_KOREA =>'韩国',
			CelebrityModel::PlACE_HK_TAIWAN_SOUTHEAST_ASIA =>'港台/东南亚',
			CelebrityModel::PlACE_CHINA =>'内地',
			CelebrityModel::PlACE_OTHER =>'其他',
	);
	public static $celebrityCategory = array(
			CelebrityModel::STARTYPES_CELEBRITIES =>'名人名流',
			CelebrityModel::STARTYPES_MOVIE =>'影视明星',
			CelebrityModel::STARTYPES_MODEL =>'模特',
			CelebrityModel::STARTYPES_SINGER =>'歌手/乐队',
			CelebrityModel::STARTYPES_SPORTS =>'体育明星',
			CelebrityModel::STARTYPES_FASHION_BLOGGERS =>'时尚博主',
			CelebrityModel::STARTYPES_FASHION_EDITOR =>'时尚编辑',
			CelebrityModel::STARTYPES_IT_GIRL =>'It Girl',
			CelebrityModel::STARTYPES_ROYAL_MEMBERS =>'王室成员',
			CelebrityModel::STARTYPES_STAR_BODY =>'明星宝贝',
			CelebrityModel::STARTYPES_IDOL =>'风格偶像',
			CelebrityModel::STARTYPES_AMERICAN_STAR =>'美剧明星',
			CelebrityModel::STARTYPES_DESIGNER =>'设计师',
			CelebrityModel::STARTYPES_OTHER =>'其他',
	);
	public static $celebritySiteState = array(
			CelebrityModel::SITE_STATE_FANS_MORE =>'粉丝最多',
			CelebrityModel::SITE_STATE_NEW_ONLINE =>'最新上线',
	);
	
	/**
	 * 得到所属星座
	 */
	public static function getStarXingZuo($monthVal,$dayVal){
		$res = "";
		switch($monthVal){
			case "1":
				if($dayVal<21){$res='魔羯座';}else{$res='水瓶座';} break;
			case "2":
				if($dayVal<20){$res='水瓶座';}else{$res='双魚座';} break;
			case "3":
				if($dayVal<21){$res='双魚座';}else{$res='白羊座';} break;
			case "4":
				if($dayVal<20){$res='白羊座';}else{$res='金牛座';} break;
			case "5":
				if($dayVal<21){$res='金牛座';}else{$res='双子座';} break;
			case "6":
				if($dayVal<22){$res='双子座';}else{$res='巨蟹座';} break;
			case "7":
				if($dayVal<23){$res='巨蟹座';}else{$res='狮子座';} break;
			case "8":
				if($dayVal<23){$res='狮子座';}else{$res='处女座';} break;
			case "9":
				if($dayVal<23){$res='处女座';}else{$res='天秤座';} break;
			case "10":
				if($dayVal<24){$res='天秤座';}else{$res='天蝎座';} break;
			case "11":
				if($dayVal<22){$res='天蝎座';}else{$res='射手座';} break;
			case "12":
				if($dayVal<22){$res='射手座';}else{$res='魔羯座';} break;
		}
		return $res;
	}
	
	public static function getCelebrityByName($starName){
	    $celebrityData = new CelebrityData;
	    return $celebrityData->getCelebrityByName($starName);
	}
	
	public static function getStarListCount(){
		$celebrityData = new CelebrityData;
		return $celebrityData->getStarListCount();
	}
	
	public static function addCelebrityClickNum($celebrityId){
		$data = new \haibao\cms\data\Celebrity();
		$data->addCelebrityClickNum($celebrityId);
	}
	
	public static function getNewVote($guessId){
		$data = new \haibao\cms\data\Celebrity();
		return $data->getNewVote($guessId);
	}
	
	/**
	 * 修改明星粉丝数,点击量
	 *  @param $editFansNum 点击量/粉丝数
	 *  @param $celebrityId 明星ID
	 *  @param $type 类型 点击量：\haibao\cms\model\data\Brand::TYPE_CLICKNUM 粉丝数：\haibao\cms\model\data\Brand::TYPE_FANSNUM
	 */
	public static function editStarFansNumByCelebrityId($editFansNum,$celebrityId,$type){
		if(!isset($editFansNum)){
			throw new BusinessException('粉丝数不能为空');
		}
		if(!$celebrityId){
			throw new BusinessException('明星ID不能为空');
		}
		$celebrityData = new CelebrityData;
		$celebrityData->editStarFansNumByCelebrityId($editFansNum,$celebrityId,$type);
	}
	
	/**
	 * 通过明星ID获取EditFansNum 粉丝数 ,点击量
	 *  @param $celebrityId 明星ID
	 *  @param $type 类型 点击量：\haibao\cms\model\data\Brand::TYPE_CLICKNUM 粉丝数：\haibao\cms\model\data\Brand::TYPE_FANSNUM
	 */
	public static function getStarFansNumByCelebrityId($celebrityId,$type){
		if(!$celebrityId){
			throw new BusinessException('明星ID不能为空');
		}
		$celebrityData = new CelebrityData;
		return $celebrityData->getStarFansNumByCelebrityId($celebrityId,$type);
	}
	
    /**
     * 添加明星
     * @param Object \haibao\cms\model\data\Celebrity $celebrityModel
     */
    public static function addCelebrity($celebrityModel){
    	
    	self::checkOperation(self::FUNC_CODE_CELEBRITY_ADD);
        self::checkCelebrity($celebrityModel);
        
        $celebrityModel->TagType = TagModel::TYPE_STAR;
        foreach($celebrityModel->CelebrityImage as $image){
        	$image->TagId = $celebrityModel->TagId;
        }
        $celebrityData = new CelebrityData();
        $userName = self::getCurrentUser()->UserName;
        self::saveOperateHistory(self::FUNC_CODE_CELEBRITY_ADD, $celebrityModel->toArray(true,true));
		$addTag = false;
		if($celebrityModel->Status == \haibao\cms\model\data\Celebrity::STATUS_ENABLE && !$celebrityModel->TagId && $celebrityModel->ParentTagId){
			$addTag = true;
		}
		$resultInsert = $celebrityData->addCelebrity($celebrityModel,$userName,$addTag);
		if($celebrityModel->ArtistInsideSecrecy){
			$celebrityModel->ArtistInsideSecrecy->ArtistId = $resultInsert->Id;
			$celebrityModel->ArtistInsideSecrecy->ArtistName = $resultInsert->NameCn;
			\haibao\cms\business\artist\ArtistInsideSecrecy::saveArtistInsideSecrecy($celebrityModel->ArtistInsideSecrecy);
		}
        return $resultInsert;
    }
    /**
     * 修改明星
     * @param Object \haibao\cms\model\data\Celebrity $celebrityModel
     */
    public static function editCelebrity($celebrityModel){
    	
    	self::checkOperation(self::FUNC_CODE_CELEBRITY_EDIT);
        self::checkCelebrity($celebrityModel);
        $celebrityData = new CelebrityData;
		// 添加明星标签
		$addTag = false;
		if($celebrityModel->Status == \haibao\cms\model\data\Celebrity::STATUS_ENABLE && !$celebrityModel->TagId && $celebrityModel->ParentTagId){
			$addTag = true;
		}
        $celebrityData->updateCelebrityById($celebrityModel,self::getCurrentUser()->UserName,$addTag);
        
        if($celebrityModel->ArtistInsideSecrecy){
        	$celebrityModel->ArtistInsideSecrecy->ArtistId = $celebrityModel->Id;
        	$celebrityModel->ArtistInsideSecrecy->ArtistName = $celebrityModel->NameCn;
        	\haibao\cms\business\artist\ArtistInsideSecrecy::saveArtistInsideSecrecy($celebrityModel->ArtistInsideSecrecy,true);
        }
        
        self::saveOperateHistory(self::FUNC_CODE_CELEBRITY_EDIT, array('id'=>$celebrityModel->Id));
        

    }
    
    /**
     * 明星库首页  添加明星投票明星猜猜猜
     */
    public static function addStarVote($id,$guessId,$userId){
    	$celebrityData = new CelebrityData();
    	$celebrity = $celebrityData->addStarVote($id,$guessId,$userId);
    }
    
    /**
     * 明星库首页  检查当前用户是否对明星般配投票
     */
    public static function checkUserVoteBanPei($userId,$relationId){
    	$celebrityData = new CelebrityData();
    	return  $celebrityData->checkUserVoteBanPei($userId,$relationId);
    }

    /**
     * 明星库首页  添加明星般配数
     */
    public static function addStarMached($matchType,$relationTableId,$userId){
    	$celebrityData = new CelebrityData();
    	$celebrity = $celebrityData->addStarMached($matchType,$relationTableId,$userId);
    }

    /**
     * 通过ID获取明星信息(所有的明星信息 包括： 图片 品牌等)
     * @param Int $id 明星ID 
     */
    public static function getCelebrityById($id){

    	// 获取明星信息 考虑是否使用filter
        $celebrityData = new CelebrityData();
        $celebrity = $celebrityData->getCelebrityById($id);
        if(empty($celebrity)){
        	
        	throw new BusinessException("明星为空",self::DATA_EMPTY_NAME);
        }
        $celebrity->CelebrityRiseCount = $celebrityData->getCelebrityRiseCountById($id);

        $celebrityInfo = new CelebrityInfoData(); 
        $celebrity->CelebrityInfo = $celebrityInfo->getCelebrityInfoByCelebrityId($id);

        $celebrityImage = new CelebrityImageData();
        $celebrity->CelebrityImage = $celebrityImage->getCelebrityImageByCelebrityId($id);

        $temp = array();
        foreach($celebrity->CelebrityImage as $image){
        	$temp[$image->ImageType] = $image;
        }
        $celebrity->CelebrityImage = $temp;

        $brandRelStarData = new BrandRelStarData();
        $celebrity->CelebrityRelBrand = $brandRelStarData->getCelebrityRelByCelebrityId($id);
        if($celebrity->CelebrityRelBrand){
        	foreach($celebrity->CelebrityRelBrand as $brand){
        		$brandName = $brand->BrandName->NameCN ? $brand->BrandName->NameCN: $brand->BrandName->NameEN;
        		$brand->BrandId = '{id:'.$brand->BrandId.',text:"'.$brandName.'"}';
        	}
        }
        $celebrityRelData = new CelebrityRelationData();
		if($celebrity->TagId){
			$celebrity->CelebrityRelStar = $celebrityRelData->getCelebrityRelByTagId($celebrity->TagId);
			if($celebrity->CelebrityRelStar){
				foreach($celebrity->CelebrityRelStar as $relStar){
					$relStar->JoinCelebrity = '{id:'.$relStar->JoinCelebrity.',text:"'.$relStar->CelebrityName.'"}';
				}
			}
		}

        return $celebrity;
    }
    
    /**
     * 根据名字判断明星是否存在
     * @param Object \haibao\cms\model\data\Celebrity $celebrityModel
     */
    public static function checkCelebrityIsExist($celebrityModel){

        $celebrityData = new CelebrityData();
        return $celebrityData->checkCelebrityIsExist($celebrityModel);
    }

    /**
     * 获取明星列表
     * @param Object \haibao\cms\model\filter\Celebrity $filter
     */
    public static function getAll($filter){
        $celebrityData = new CelebrityData();
        return $celebrityData->getAll($filter);
    }
    
    public static function getStarByIds($starIds,$isMessage = false){
    	$starArr = array();
    	if(empty($starIds)){
    		throw new BusinessException('明星ID不存在！',self::DATA_EMPTY);
    	}
    	$filter = new \haibao\cms\model\filter\Celebrity();
    	$filter->select(array(
    			CelebrityFilter::CONDITION_FIELD_NAME_ID,
    			CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID,
    			CelebrityFilter::CONDITION_FIELD_NAME_NAME_CN,
    			CelebrityFilter::CONDITION_FIELD_NAME_NAME_EN,
    	));
    	$filter->where(CelebrityFilter::CONDITION_FIELD_NAME_ID,\haibao\frame\data\query\Condition::CONDITION_IN,$starIds);
    	$filter->where(CelebrityFilter::CONDITION_FIELD_NAME_STATUS, \haibao\frame\data\query\Condition::CONDITION_EQUAL, \haibao\cms\model\data\Celebrity::STATUS_ENABLE);
    	
    	$starList = self::getAll($filter);
    	
    	$tagList = \haibao\cms\business\Tag::getAllTagDict();
    
    	foreach($starList as $list){
    		if(!empty($tagList[$list->TagId])){
    			$list->TopicId = $tagList[$list->TagId]['TopicId'];
    			$starArr[$list->Id] = $list;
    		}
    	}
    	if($isMessage){
    	    $celebrityArr = array();
    	    if($starArr){
    	        foreach ($starArr as $k=>$v){
    	            $celebrityArr[$v->Id]['Title'] = $v->NameCn.'('.$v->NameEn.')';
    	            /* if(self::$isPc){} */
    	            $celebrityArr[$v->Id]['Url'] = \haibao\classlibrary\www\Config::getConfig(\haibao\classlibrary\www\Config::CLASSLIBRARY_CONFIG_HOST_STARS).'/star/'.$v->TopicId.'/';
    	        }
    	    }
    	    return $celebrityArr;
    	}else{
    	    return $starArr;
    	}
    }
    
    /**
     * 获取明星列表
     * @param Object \haibao\cms\model\filter\Celebrity $filter
     */
    public static function getAllByImage($filter){
    	$celebrityData = new CelebrityData();
    	return $celebrityData->getAll($filter);
    }
    
    /**
     * 获取单个明星
     * @param Object \haibao\cms\model\filter\Celebrity $filter
     */
    public static function getOne($filter){
    	$celebrityData = new CelebrityData();
    	return $celebrityData->getOne($filter);
    }
    /**
     * 添加明星(其他模块使用)
     * @param Object \haibao\cms\model\data\Celebrity $celebrityModel
     * @param Object \haibao\cms\model\data\CelebrityInfo $celebrityInfoModel
     */
    public static function addCelebrityForOther($celebrityModel){
        
    	$celebrityInfoModel = new \haibao\cms\model\data\CelebrityInfo();
    	$celebrityModel->CelebrityInfo = $celebrityInfoModel;
    	
    	$celebrityModel->Description = '';
    	$celebrityModel->AddTime = $celebrityModel->UpdateTime = date('Y-m-d H:i:s');
    	
    	$chineseSpell = new ChineseSpell();
    	$nameCn  = strtoupper(substr($chineseSpell->getFullSpell($celebrityModel->NameCn," "),0,1));
    	
    	$chineseSpell = new ChineseSpell();
    	$nameEn  = strtoupper(substr($chineseSpell->getFullSpell($celebrityModel->NameEn," "),0,1));
    	$celebrityModel->PinyinCh = $nameCn;
    	$celebrityModel->PinyinEn = $nameEn;
    	
    	if(!self::checkCelebrityIsExist($celebrityModel)){
    		$userName = self::getCurrentUser()->UserName;
        	$celebrityData = new CelebrityData();
        	$celebrityData->addCelebrityForOther($celebrityModel,$userName);
    	}else{
    		return false;
    	}
    	return true;
    }
        
 

    /**
     * 获取明星操作记录
     * @param : Object \haibao\model\filter\CelebrityEditLog $filter
     */
    public static function getEditLog($filter){
        
        $data = new \haibao\cms\data\CelebrityEditLog();
        return $data->getAll($filter);    
    }
    
    /**
     * 根据明星ID获取明星图像
     * @param : String $ids
     */
    public static function getCelebrityImages($ids){
    	$data = new CelebrityImageData();
    	return $data->getCelebrityImagesByIds($ids);
    }
    
    /**
     * 根据明星ID删除明星
     */
    public static function deleteCelebrityById($celebrityId ,$status = \haibao\cms\model\data\Celebrity::STATUS_DISABLE){

    		self::checkOperation(self::FUNC_CODE_CELEBRITY_DELETE);
    		$data = new CelebrityData();
    		$data->deleteCelebrityById($celebrityId, $status);
  			self::saveOperateHistory(self::FUNC_CODE_CELEBRITY_DELETE, array($celebrityId,$status));
    }
    
    /**
     * 获取明星类别
     */
    public static function getStarTypes($StarTypes){
    	$data = array();
    	if(!empty($StarTypes)){
    
    		$StarTypes = preg_replace('/\[|\]/i','',$StarTypes);
    		$data = array_flip(explode(',', $StarTypes));
    	}
    	
    	return $data;
    }
    /*
     * 根据标签ID更新明星信息
    * @param : object \haibao\cms\model\data\Celebrity $celebrityModel
    */
    public static function UpdateCelebrityByTagId($celebrityModel){
    	$celebrityModel->UpdateTime = new \DateTime();
    	$arrSet = array(
    			CelebrityFilter::CONDITION_FIELD_NAME_NAME_CN=>$celebrityModel->NameCn,
    			CelebrityFilter::CONDITION_FIELD_NAME_NAME_EN=>$celebrityModel->NameEn,
    			CelebrityFilter::CONDITION_FIELD_NAME_UPDATE_TIME=>$celebrityModel->UpdateTime
    	);
    	$filter = new CelebrityFilter();
    	$filter->where(CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID,Condition::CONDITION_EQUAL,$celebrityModel->TagId);

    	$data = new CelebrityData();
    	$data->updateCelebrityByFilter($arrSet,$filter,$celebrityModel);
    
    }
    
    /**
     * 修改明星评论数
     * @param unknown_type $starId
     * @param unknown_type $userId
     * @param unknown_type $num
     * @param unknown_type $isSub
     * @throws \haibao\cms\business\BusinessException
     */
    public static function updateCommentNum($starId,$userId,$num=1,$isSub=false){
    	if(!$starId){
    		throw new \haibao\cms\business\BusinessException('Id不能为空');
    	}
    	$data = new CelebrityData();
    	$data->updateCommentNum((int)$starId,$userId,$num,$isSub);
    }
    
    
    
    /**
     * 校验明星信息
     * @param Object \haibao\cms\model\data\Celebrity $model
     */
    private static function checkCelebrity($model){
    
    	if(empty($model->NameCn) && empty($model->NameEn)){
    		throw new BusinessException('中文/英文名必须添一项',self::DATA_EMPTY_NAME);
    	}else{
    		$chineseSpell = new ChineseSpell();
    		$nameCn  = strtoupper(substr($chineseSpell->getFullSpell($model->NameCn," "),0,1));
    
    		$chineseSpell = new ChineseSpell();
    		$nameEn  = strtoupper(substr($chineseSpell->getFullSpell($model->NameEn," "),0,1));
    		$model->PinyinCh = $nameCn;
    		$model->PinyinEn = $nameEn;
    		 
    	}
    	if(!$model->Gender){
    		throw new BusinessException('性别为空',self::DATA_EMPTY_NAME);
    	}
    	if(!$model->StarTypes){
    		throw new BusinessException('职业为空',self::DATA_EMPTY_NAME);
    	}
    	if(!$model->Place){
    		throw new BusinessException('发展地域为空',self::DATA_EMPTY_NAME);
    	}
    }
    
    /**
     * 添加明星标签
     * @param Object \haibao\cms\model\data\Celebrity $celebrityModel
     */
    private static function addTag($celebrityModel){
    
    	$tagModel = new TagModel;
    	$tagModel->TagName = $celebrityModel->NameCn;
    	$tagModel->TagStatus = TagModel::STATUS_ENABLE;
    	$tagModel->ParentId = $celebrityModel->ParentTagId;
    	$tagModel->TagType = TagModel::TYPE_STAR;
    	$celebrityModel->TagId = Tag::addTag($tagModel,true);
    
    }
    public static function deleteCelebrityByTagId($tagId){
    	if($tagId){
    		$data = new CelebrityData();
    		$celebrityFilter = new CelebrityFilter();
    		$celebrityFilter->where(CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_EQUAL, $tagId);
    		$data->deleteCelebrityByTagId($tagId,$celebrityFilter);
    	}
    }
    
    /**
     * 通过标签获取明星信息
     */
    public static function getCelebrityInfoByTagIds($tagIds){
        $celebrityInfo = null;
        if($tagIds){
            $data = new CelebrityData();
            $celebrityFilter = new CelebrityFilter();
            $celebrityFilter->select(array(
                CelebrityFilter::CONDITION_FIELD_NAME_ID,
                CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID,
                CelebrityFilter::CONDITION_FIELD_NAME_NAME_CN,
                CelebrityFilter::CONDITION_FIELD_NAME_NAME_EN
        				));
            $celebrityFilter->where(CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_IN, $tagIds);
            $celebrityInfo = $data->getAll($celebrityFilter);
        }
        return $celebrityInfo;
    }
    
    /**
     * 通过标签获取明星信息
     */
    public static function getCelebrityProInfoByTagIds($tagIds){
        $celebrityInfo = null;
        if($tagIds){
            $data = new CelebrityData();
            $celebrityFilter = new CelebrityFilter();
            $celebrityFilter->select(array(
                CelebrityFilter::CONDITION_FIELD_NAME_ID,
                CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID,
                CelebrityFilter::CONDITION_FIELD_NAME_NAME_CN,
                CelebrityFilter::CONDITION_FIELD_NAME_NAME_EN,
                CelebrityFilter::CONDITION_FIELD_NAME_BIRTHDAY,
            ));
            $celebrityFilter->where(CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_IN, $tagIds);
            $celebrityFilter->where(CelebrityFilter::CONDITION_FIELD_NAME_STATUS, Condition::CONDITION_EQUAL, \haibao\cms\model\data\Celebrity::STATUS_ENABLE);
            $celebrityInfoFilter = new \haibao\cms\model\filter\CelebrityInfo();
            $celebrityInfoFilter->select(array(
                $celebrityInfoFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,
                $celebrityInfoFilter::CONDITION_FIELD_NAME_REP_WORKS,
                $celebrityInfoFilter::CONDITION_FIELD_NAME_XING_ZUO
            ));
            $celebrityFilter->leftjoin($celebrityInfoFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,$celebrityInfoFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITYINFO,false);
            
            $celebrityRiseCountFilter = new CelebrityRiseCountFilter();
            $celebrityRiseCountFilter->select(array(
                $celebrityRiseCountFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,
                $celebrityRiseCountFilter::CONDITION_FIELD_NAME_EDIT_FANS_NUM
            ));
            $celebrityFilter->leftjoin($celebrityRiseCountFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityRiseCountFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITY_RISECOUNT,false);
            
            $celebrityImageFilter = new CelebrityImageFilter();
            $celebrityImageFilter->select(array(
                CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,
                CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_ID
            ));
            $celebrityFilter->leftjoin($celebrityImageFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITYIMAGE,false);
            $celebrityImageFilter->where(CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\CelebrityImage::IMAGE_TYPE_PICTURE);
            
            $celebrityInfo = $data->getAll($celebrityFilter);
    
            $tagList = \haibao\cms\business\Tag::getAllTagDict();
            if($celebrityInfo){
                foreach($celebrityInfo as $list){
                    if(!empty($tagList[$list->TagId])){
                        $list->CelebrityUrl = $tagList[$list->TagId]['TopicId'];
                    }
                }
            }
        }
        return $celebrityInfo;
    }
    
    /**
     * 通过标签获取明星信息
     */
    public static function getCelebrityInfoByTagId($tagId){
    	$celebrityInfo = null;
    	if($tagId){
    		$data = new CelebrityData();
    		$celebrityFilter = new CelebrityFilter();
    		$celebrityFilter->select(array(
    				CelebrityFilter::CONDITION_FIELD_NAME_ID,
    				CelebrityFilter::CONDITION_FIELD_NAME_NAME_CN,
    				CelebrityFilter::CONDITION_FIELD_NAME_NAME_EN,
    				CelebrityFilter::CONDITION_FIELD_NAME_DESCRIPTION,
    				CelebrityFilter::CONDITION_FIELD_NAME_BIRTHDAY,
    				CelebrityFilter::CONDITION_FIELD_NAME_PLACE,
    				));
    		$celebrityFilter->where(CelebrityFilter::CONDITION_FIELD_NAME_TAG_ID, Condition::CONDITION_EQUAL, $tagId);
    		$celebrityInfoFilter = new CelebrityInfoFilter();
    		$celebrityInfoFilter->select(array(
    				CelebrityInfoFilter::CONDITION_FIELD_NAME_BLOOD,
    				CelebrityInfoFilter::CONDITION_FIELD_NAME_HEIGHT,
    		));
    		$celebrityImageFilter = new CelebrityImageFilter();
    		$celebrityImageFilter->select(array(
    				CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,
    				CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_ID
    				));
    		$celebrityFilter->leftjoin($celebrityInfoFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityInfoFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITYINFO,false);
    		$celebrityFilter->leftjoin($celebrityImageFilter,null,CelebrityFilter::CONDITION_FIELD_NAME_ID,CelebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,CelebrityFilter::CONDITION_FIELD_NAME_CELEBRITYIMAGE,false);
    		$celebrityImageFilter->where(CelebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\CelebrityImage::IMAGE_TYPE_PICTURE);
    		$celebrityInfo = $data->getOne($celebrityFilter);
    	}
    	return $celebrityInfo;
    }
    
    /**
     * 获取明星风云榜排行
     * @param array $rankConditions
     * ['gender']['starType']['rankType']
     */
    public static function getCelebrityForRank($rankConditions){
    	$data = new CelebrityData();
    	return $data->getCelebrityForRank($rankConditions);
    }
    
    public static function getCelebrityInfoById($id){
    	if($id){
    		$celebrityInfo = new CelebrityInfoData();
    		return $celebrityInfo->getCelebrityInfoByCelebrityId($id);
    	}else{
    		throw new BusinessException('ID不允许为空',self::DATA_EMPTY_ID);
    	}
    }
    
    public static function UpdateCelebrityInfo($queryArr){
    	$celebrityInfo = new CelebrityInfoData();
    	return $celebrityInfo->UpdateCelebrityInfo($queryArr);
    }
    
    public static function getCelebrityWishVideoById($id){
    	if($id){
    		$celebrityInfo = new CelebrityInfoData();
    		return $celebrityInfo->getCelebrityWishVideoById($id);
    	}else{
    		throw new BusinessException('ID不允许为空',self::DATA_EMPTY_ID);
    	}
    }
    
    public static function getAllCelebrityIdByWeight(){
    	$data = new CelebrityData();
    	return $data->getAllCelebrityIdByWeight();
    }
    
    public static function getAvatarImageByCelebrityId($useImageId){
    	$imageUrls = \haibao\cms\business\ImageLibrary::getImageUrlById(array($useImageId));
    	$articleContent = new \haibao\cms\common\ArticleContent();
    	$staticUrl = $articleContent->replaceImageLink($imageUrls[$useImageId],300,300,100,0);
    	return $articleContent->replaceImgUrlCDNLink($staticUrl);
    }
    
    public static function getCelebrityProperty($celebrityId){
    	if(!$celebrityId){
    		throw new \haibao\cms\business\BusinessException('Id不能为空');
    	}
    	$data = new \haibao\cms\data\Celebrity();
    	return $data->getCelebrityProperty($celebrityId);
    
    }
    
    /**
     * 计划任务使用获取明星的个人信息
     * @param unknown $celebrityId
     */
    public static function getCelebrityByIdForPublish($celebrityId,$isHasDesc = true){
    	$celebrityFilter = new CelebrityFilter();
    	
    	$selectArr = array(
    		$celebrityFilter::CONDITION_FIELD_NAME_ID,
    		$celebrityFilter::CONDITION_FIELD_NAME_TAG_ID
    			);
    	if($isHasDesc){
    		$selectArr = array(
    		$celebrityFilter::CONDITION_FIELD_NAME_ID,
    		$celebrityFilter::CONDITION_FIELD_NAME_TAG_ID,
    		$celebrityFilter::CONDITION_FIELD_NAME_NAME_CN,
    		$celebrityFilter::CONDITION_FIELD_NAME_NAME_EN,
    		$celebrityFilter::CONDITION_FIELD_NAME_BIRTHDAY,
    		$celebrityFilter::CONDITION_FIELD_NAME_STAR_TYPES,
    		$celebrityFilter::CONDITION_FIELD_NAME_PLACE,
    		$celebrityFilter::CONDITION_FIELD_NAME_DESCRIPTION,
    		);
    	}
    	
    	$celebrityFilter->select($selectArr);
    	
    	$celebrityImageFilter = new CelebrityImageFilter();
    	$celebrityImageFilter->select(array(
    		$celebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,
    		$celebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_ID,
    		$celebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_TYPE,
    	));
    	
    	if(is_array($celebrityId)){
    		$celebrityFilter->where($celebrityFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_IN, $celebrityId);
    	}else{
    		$celebrityFilter->where($celebrityFilter::CONDITION_FIELD_NAME_ID, Condition::CONDITION_EQUAL, $celebrityId);
    	}
    	$celebrityImageFilter->where($celebrityImageFilter::CONDITION_FIELD_NAME_IMAGE_TYPE,Condition::CONDITION_EQUAL,\haibao\cms\model\data\CelebrityImage::IMAGE_TYPE_PICTURE);
    	$celebrityFilter->leftJoin($celebrityImageFilter,null,$celebrityFilter::CONDITION_FIELD_NAME_ID,$celebrityImageFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,$celebrityFilter::CONDITION_FIELD_NAME_CELEBRITY_IMAGE,false);
    	
    	if($isHasDesc){
    		$celebrityInfoFilter = new CelebrityInfoFilter();
    		$celebrityInfoFilter->select(array(
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_BLOOD,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_EC_COMPANY,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_HEIGHT,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_SUCCESS,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_REP_WORKS,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_FAMILY,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_XING_ZUO,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_VIDEO_IMAGE_ID,
    				$celebrityInfoFilter::CONDITION_FIELD_NAME_VIDEO_URL,
    		));
    	
    		$celebrityFilter->leftJoin($celebrityInfoFilter,null,$celebrityFilter::CONDITION_FIELD_NAME_ID,$celebrityInfoFilter::CONDITION_FIELD_NAME_CELEBRITY_ID,$celebrityFilter::CONDITION_FIELD_NAME_CELEBRITYINFO,false);
    	}
    	
    	$celebrityData = self::getAll($celebrityFilter);
    	if($celebrityData){
    		if(is_array($celebrityId)){
    			return $celebrityData;
    		}else{
    			return $celebrityData[0];
    		}
    	}
    }
    
    /**
     * 获取明星的美剧资讯
     */
    public static function getTvInfoByTagId($tagId){
    	$data = new \haibao\cms\data\Celebrity();
    	return $data->getTvInfoByTagId($tagId);
    }
    
    /**
     * 根据明星的Id获取明星的Tag
     * @param unknown $celebrityIds
     * @return multitype:NULL
     */
    public static function getTagIdByCelebrityId($celebrityId){
    	$data = new \haibao\cms\data\Celebrity();
    	return $data->getTagIdByCelebrityId($celebrityId);
    }
    
    /**
     * 获取明星详情页的热门图片(文章)
     */
    public static function getHotPicArticles($tagId,$hotTags){
    	$data = new \haibao\cms\data\Celebrity();
    	return $data->getHotPicArticles($tagId,$hotTags);
    }
    /**
     * 获取明星详情页的热门图片(图集)
     */
    public static function getHotPicImageColl($tagId,$hotTags){
    	$data = new \haibao\cms\data\Celebrity();
    	return $data->getHotPicImageColl($tagId,$hotTags);
    }
    
    public static function getOneNewImage($tagId,$notInArticleIds,$notInImageCollIds){
    	$data = new \haibao\cms\data\Celebrity();
    	return $data->getOneNewImage($tagId,$notInArticleIds,$notInImageCollIds);
    }

	public static function saveSimplifyCelebrity($model){
		$model->Editor = self::getCurrentUser()->Id;
		$model->AddTime = new \DateTime();
		$model->TagType = TagModel::TYPE_STAR;;
		$celeInfoModel = new \haibao\cms\model\data\CelebrityInfo();
		$model->CelebrityInfo = $celeInfoModel;
		$data = new \haibao\cms\data\Celebrity();
		$resModel = $data->addCelebrityForOther($model,self::getCurrentUser()->UserName,false);
		return $resModel->Id;
	}
	
	public static function getLibraryStarRecommend(){
	    $data = new \haibao\cms\data\Celebrity();
    	return $data->getLibraryStarRecommend();
	}
	
	public static function UpdateCelebrityTimeById($id){
	    $data = new \haibao\cms\data\Celebrity();
	    return $data->UpdateCelebrityTimeById($id);
	}
    
}
